package ifSwitchPlugins;

public class IfElseNumbers {
	// Generates a random number and prints whether it is even or odd
	public void numberGenerator(){
	    if ((int)(Math.random()*100)%2 == 0) {
	        System.out.println("The number is even");
	    } else {
	        System.out.println("The number is odd");
	    }
	}
	
	// Converts the time, which is in milliseconds, into a
    // more readable format with higher units
    public String getTimeUnit(long time) {
        String unit = "ms";
        if (time >= 365*24*60*60*1000L) {
            unit = "years";
            time /= 365*24*60*60*1000L;
        } else if (time >= 24*60*60*1000) {
            unit = "days";
            time /= 24*60*60*1000;
        } else if (time >= 60*60*1000) {
            unit = "hr";
            time /= 60*60*1000;
        } else if (time >= 60*1000) {
            unit = "min";
            time /= 60*1000;
        } else if (time >= 1000) {
            unit = "sec";
            time /= 1000;
        }
        // Execution continues here if any of the conditions match
        return time + " " + unit;
    }
    
    public int doOperation(int operation, int x, int y){
    	int result;
    	switch (operation) {
		case 0:
			result = x+y;
			break;
		case 1:
			result = x-y;
			break;
		case 2:
			result = x*y;
			break;
		case 3:
			result = x/y;
			break;
		default:
			result = x-y;
		}
    	return result;
    }
}
